/**
 * @projectName gs_online
 * @package com.answer.wx.gateway.controller
 * @className com.answer.wx.gateway.controller.SearchController
 */
package com.answer.wx.gateway.controller;

import com.answer.wx.common.aop.ApiOptions;
import com.answer.wx.dao.model.Message;
import com.answer.wx.gateway.bean.MessageBean;
import com.answer.wx.gateway.service.MessageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * SearchController
 * @description 搜索类
 * @author answer_wx
 * @date 2022/8/15 16:08
 * @version 1.0
 */
@RestController
@RequestMapping("/search")
@Api(value = "搜索", tags = {"搜索展示"})
@Slf4j
public class SearchController {
    @Autowired
    private MessageService messageService;

    @PostMapping("/{categoryId}")
    @ApiOperation("获取搜索结果")
    @ApiOptions
    public List<MessageBean> search(@PathVariable Integer categoryId, String keyword) {
        List<MessageBean> all = messageService.
                getMessageByCategoryAndKeyword(categoryId, keyword);
        return messageService.getImage(all);
    }

    @PostMapping("/getMessageByKeyword")
    @ApiOperation("获取搜索结果")
    @ApiOptions
    public List<MessageBean> getMessageByKeyword(String keyword, Integer pageNumber){
        return messageService.getMessageByKeyword(keyword, pageNumber);
    }

}